package com.atguigu.gulimallcart.vo;

import java.math.BigDecimal;
import java.util.List;

public class Cart {
    private List<CartItem> items;
    /**
     * 商品数量
     */
    private Integer countNum;

    /**
     * 商品类型数量
     */
    private Integer countType;

    private BigDecimal totalAmount;

    private BigDecimal reduce = new BigDecimal(0);

    public List<CartItem> getItems() {
        return items;
    }

    public void setItems(List<CartItem> items) {
        this.items = items;
    }

    public Integer getCountNum() {
        Integer count = 0;
        if(items!=null&& this.items.size()>0){
            for (CartItem item : items) {
                count += item.getCount();
            }
        }
        return count;
    }

    public Integer getCountType() {
        return this.items==null?0:this.items.size();
    }


    public BigDecimal getTotalAmount() {
        BigDecimal decimal = new BigDecimal(0);
        if(items!=null&& this.items.size()>0){
            for (CartItem item : items) {
                if(item.getCheck()){
                    BigDecimal totalPrice = item.getTotalPrice();
                    decimal = decimal.add(totalPrice);
                }
            }
        }
        BigDecimal subtract = decimal.subtract(getReduce());
        return subtract;
    }

    public void setTotalAmount(BigDecimal totalAmount) {
        this.totalAmount = totalAmount;
    }

    public BigDecimal getReduce() {
        return reduce;
    }

    public void setReduce(BigDecimal reduce) {
        this.reduce = reduce;
    }
}
